<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Login</title>
    <script src="${base}/js/jquery.min.js"></script>
    <script src="${base}/js/jsencrypt/jsencrypt.min.js"></script>
    
    <script src="${base}/js/crytojs/components/core.js"></script>
    <script src="${base}/js/crytojs/components/enc-base64.js"></script>
    
    
    
<script type="text/javascript">

function jsEncode(){
	var encrypt = new JSEncrypt();
	var pubk = $("#public_key").val();
    encrypt.setPublicKey(pubk);
    var text = $("#text").val();
    
    var dataBase64 = encrypt.encrypt(text);
    
    //base64转为byte数组
	var parsedWordArray = CryptoJS.enc.Base64.parse(dataBase64);
  //byte数组转Hex
    var encryptedHexStr = CryptoJS.enc.Hex.stringify(parsedWordArray);
    
	$("#encode_text").val(encryptedHexStr);
}   

function jsDecode(){
	var encrypt = new JSEncrypt();
	var prik = $("#private_key").val();
    encrypt.setPrivateKey(prik);
    var encodeText = $("#encode_text").val();
    
    //Hex转为byte数组
    var hexWord2Array = CryptoJS.enc.Hex.parse(encodeText);
    //byte数组转base64
	var dataBase64 = CryptoJS.enc.Base64.stringify(hexWord2Array); 
    
    var data = encrypt.decrypt(dataBase64);
	alert(data);
}



function javaDecode(){
	var encode_text = $("#encode_text").val();
    $.ajax({
        url: "${base}/rsa/hutool/decode",
        data: {"hexEncodeText": encode_text}, 
        type: 'post',
        success: function (msg) {
            alert(msg);
        }
    });
}

function javaEncode(){
	var content = $("#text").val();
    $.ajax({
        url: "${base}/rsa/hutool/encode",
        data: {"text": content}, 
        type: 'post',
        success: function (data) {
            alert(data);
            $("#encode_text").val(data);
        }
    });
}
</script>
</head>
<body>
    <div>

        
        私钥:<textarea  rows="5" id="private_key"  cols="65">${private_key !}</textarea>
        <hr/>
       公钥:<textarea rows="5" id="public_key"  cols="65">${public_key !}</textarea>
        <hr/>
   明文: <input type="text" id="text" value="woshi中国@.com">
   <hr/>
      <input type="button" onclick="jsEncode()" value="前端加密" />
      <hr/>
   密文:  <textarea type="text" id="encode_text" rows="5" cols="65"></textarea>
   <hr/>
     <input type="button" onclick="javaDecode()" value="后端解密" /> 
   <hr/>
   
  <hr/>
     <input type="button" onclick="javaEncode()" value="后端加密" /> 
   <hr/>
  <hr/>
     <input type="button" onclick="jsDecode()" value="前端解密" /> 
   <hr/>
   
    </div>
</body>
</html>